<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function foo(fn,arr){
        var a = [];
        for (var i in arr){
            if (fn(arr[i])){
                a.push(arr[i])
            }
        }
        return a;
    }

    function isOs(num){
        if (num%2==0){
            return true;
        } else {
            return false;
        }
    }
    function isJs(num){
        if (num%2==1){
            return true;
        } else {
            return false;
        }
    }
    var arr = [12,23,34,53,46,86];
    var b = foo(isOs,arr);
    var c = foo(isJs,arr);

    function myForeach(arr,fn){
        for(var i in arr){
            fn(i,arr[i])
        }
    }
    myForeach(arr,function(ii,v){
       //alert(v)
        console.log(ii);
        console.log(v);
    });

    function myMap(arr,fn){
        var a = [];
        for (var i in arr){
            if (fn(arr[i])){
                a.push(arr[i])
            }
        }
        return a;
    }

    var cc = myMap(arr,function (v){
        if (v<20) {
            return true;
        } else {
            return false
        }
    })
</script>
</body>
</html>